﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace RainmeterCustomized
{
    public class ImageTools
    {
        public enum Position
        {
            Below = 0,
            Right = 1,
        }
        public static Image taskViewShot()
        {
            Rectangle rc = Screen.PrimaryScreen.Bounds;
            int iWidth = rc.Width;
            int iHeight = rc.Height;
            int a = Screen.PrimaryScreen.WorkingArea.Height;
            int b = iHeight;

            Image myImage = new Bitmap(iWidth, b-a);           
            Graphics.FromImage(myImage).CopyFromScreen(new System.Drawing.Point(0, a), new System.Drawing.Point(0, 0), new System.Drawing.Size(iWidth, b-a));
            return myImage;
        }

        public static Image screenShot()
        {
            Rectangle rc = Screen.PrimaryScreen.Bounds;
            int iWidth = rc.Width;
            int iHeight = rc.Height;
            Image myImage = new Bitmap(iWidth, iHeight);
            Graphics.FromImage(myImage).CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size(iWidth, iHeight));
            return myImage;
        }

        public static Image mergeImage(Image img1, Image img2, Position position)
        {
            if (img1 == null || img2 == null)
            {
                return null;
            }
            Int32 newWidth = 0;
            Int32 newHeight = 0;
            Point p = new Point(0, 0);
            if (position == Position.Below)
            {
                newWidth = (img1.Width > img2.Width) ? img1.Width : img2.Width;
                newHeight = img1.Height + img2.Height;
                p = new Point(0, img1.Height);
            }
            else if (position == Position.Right)
            {
                newWidth = img1.Width + img2.Width;
                newHeight = (img1.Height > img2.Height) ? img1.Height : img2.Height;
                p = new Point(img1.Width, 0);
            }
            else
            {
                return null;
            }
            Image newImage = new Bitmap(newWidth, newHeight);
            Graphics graphics = Graphics.FromImage(newImage);
            graphics.DrawImage(img1, new Point(0, 0));
            graphics.DrawImage(img2, p);
            graphics.Dispose();
            return newImage;
        }
    }
}
